﻿using System;
using System.Windows.Forms;

namespace MQAMS
{
    public partial class FrmMain : Form
    {
        #region Private Fields

        private string _attendanceFile;

        private string _scheduleFile;

        #endregion

        public FrmMain()
        {
            InitializeComponent();
        }

        private void btnAttendance_Click(object sender, EventArgs e)
        {
            DialogResult result = ofdAttendance.ShowDialog(this);
            if (result == DialogResult.OK)
            {
                _attendanceFile = ofdAttendance.FileName;
                lblAttendance.Text = _attendanceFile;
            }
        }

        private void btnSchedule_Click(object sender, EventArgs e)
        {
            DialogResult result = ofdSchedule.ShowDialog(this);
            if (result == DialogResult.OK)
            {
                _scheduleFile = ofdSchedule.FileName;
                lblSchedule.Text = _scheduleFile;
            }
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            ExportXls();
            btnExport.Enabled = true;
        }

        private void ExportXls()
        {
            btnExport.Enabled = false;
            var sm = new ScheduleManager(_scheduleFile);
            new AttendanceManager(_attendanceFile, sm.GetSchedules());
            XlsHelper.Instance.ExportXls(_attendanceFile.Substring(0, _attendanceFile.LastIndexOf('\\') + 1));
        }
    }
}